//==================风控中心-organization_risk_list.js


//触发列表刷新事件
function reloadList(fromListId) {
    doReloadList({pageIndex: 1, node: {id: fromListId}});
}

//列表刷新
function doReloadList(evt) {
    var list = h3ui.widgets[evt.node.id];

    var queryId = list.childIds.find(a => a.includes("ModelQueryForm"));

    var filter = h3ui.widgets[queryId].props.value || {};

    filter = JSON.parse(JSON.stringify(filter));

    var pageId = list.childIds.find(a => a.includes("Pagination"));

    var pageIndex = h3ui.widgets[pageId].props.current;
    var pageSize = h3ui.widgets[pageId].props.pageSize;


    list.emit("load", {pageIndex, pageSize, filter});


    list.props.selectedRowKeys = [];
    list.props.selectedRow = [];

}


var fieldRequired = ["name", "license_code", "credit_identifier", "legal_representative", "registered_capital", "address", "contact", "org_risk_status"];

var initRiskForm = true;

// 打开新增
function openAddModal() {

    var modal = h3ui.widgets.CustomModal1;
    var dataSource = h3ui.models.t_organization_risk;
    //第一次初始化
    if (initRiskForm) {
        dataSource.schema.properties.filter(a => fieldRequired.includes(a.code)).forEach(a => a.required = true);
        initRiskForm = false;
    }

    dataSource.newItem();
    modal.props.title = '新增';
    modal.props.visible = true;
}


// 打开修改
function openMidfyModal() {

    var list = h3ui.widgets["FormList3"];

    var rows = list.props.selectedRow;


    if (rows.length != 1) {
        h3ui.$message.info("请选择且只能选择一行数据");
        return;
    }

    var modal = h3ui.widgets.CustomModal1;
    var dataSource = h3ui.models.t_organization_risk;
    //第一次初始化
    if (initRiskForm) {
        dataSource.schema.properties.filter(a => fieldRequired.includes(a.code)).forEach(a => a.required = true);
        initRiskForm = false;
    }

    dataSource.newItem();

    dataSource.item = rows[0];
    modal.props.title = '修改';
    modal.props.visible = true;

}


//风控表单提交新增和修改
function submitRisk() {

    var action = h3ui.widgets.CustomModal1.props.title;
    var submitService;
    if (action == "新增") {
        submitService = h3ui.models.t_organization_risk.createBO;
    } else if (action == "修改") {
        submitService = h3ui.models.t_organization_risk.updateBO;
    } else {
        h3ui.$message.warn("提交失败,action=" + action);
        return;
    }
    submitService().then(res => {
        h3ui.$message.info("提交成功");
        reloadList("FormList3");
        h3ui.widgets.CustomModal1.props.visible = false;
    })
}

//风控表单重置
function resetRisk() {
    h3ui.models.t_organization_risk.newItem();
}


//进入企业准入页面
function enterpriseAccess() {

    var keys = h3ui.widgets.FormList3.props.selectedRowKeys;

    if (keys.length != 1) {
        h3ui.$message.info("请选择且只能选择一行数据");
        return;
    }


    var riskId = keys[0];
    var mode = "detail";

    h3ui.openPage('innerLink', "risk_management", 'self', {riskId, mode});

}